$(function () {
    var clientbill_datagrid = $("#clientbill_datagrid");
    var clientbill_dialog = $("#clientbill_dialog");
    var clientbill_form = $("#clientbill_form");

    var cmdObj = {
        //工具栏的刷新
        reload: function () {
            clientbill_datagrid.datagrid("reload");
        },

        //工具栏添加
        add: function () {
            //添加与编辑时
            clientbill_form.form("clear");
            //1.弹框
            clientbill_dialog.dialog("open");
            //设置标题
            clientbill_dialog.dialog("setTitle", "员工添加");
        },
        //拘审
        edit: function () {
            //判断是否选中数据
            var row = clientbill_datagrid.datagrid("getSelected");
            /*如果没选中数据*/
            if (!row) {
                $.messager.alert('温馨提示', "请选择要编辑的数据");
                return;
            }
            //添加与编辑时将数据清空
            clientbill_form.form("clear");
            //部门名字不一样, 需要修改
            if (row.clientbill) {
                row["clientbill.id"] = row.clientbill.id;
            }
            //数据回显: 同名原则
            clientbill_form.form("load", row);
            //1.弹框
            clientbill_dialog.dialog("open");
            //设置标题
            clientbill_dialog.dialog("setTitle", "员工编辑");
        },

        //拘审
        resufe: function () {
            //判断是否选中数据
            var row = clientbill_datagrid.datagrid("getSelected");
            if (!row) {
                $.messager.alert('温馨提示', "请选择要编辑的数据");
                return;
            }
            $.messager.confirm('确认', '您确认想要执行这个操作吗？', function (r) {
                if (r) {
                    $.get("/clientbill/changeState", {id: row.id}, function (data) {
                        if (data.success) {
                            //刷新列表数据
                            clientbill_datagrid.datagrid("reload");
                        } else {
                            $.messager.alert('温馨提示', data.msg);
                        }
                    })
                }
            });
        },
        //关闭
        cancel: function () {
            clientbill_dialog.dialog("close");
        }
    }

    //调用
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        cmdObj[cmd]();
    });

    clientbill_datagrid.datagrid({
        url: "clientbill/list",
        fit: true,
        fitColumns: true,
        striped: true,
        singleSelect: true,
        pagination: true,
        rownumbers: true,
        columns: [[
            {field: "ck", checkbox: true},//显示多选框样式
            {field: "id", hidden: true},
            {field: "status", title: "客户姓名", width: 100},
            {field: "guaranteebillId", title: "性别", width: 100},
            {field: "client", title: "联系方式", width: 100},
            {field: "otime", title: "邮箱", width: 100},
            {field: "duty", title: "微信", width: 100}

        ]],
        toolbar: '#cb',
        onClickRow: function (index, row) {
            //根据员工的状态修改离职/复职按钮的显示
            if (row.state == 1) {
                $("#change_btn").linkbutton({
                    text: "停用"
                });
            } else {
                $("#change_btn").linkbutton({
                    text: "正常"
                })
            }
        }
    });
    clientbill_dialog.dialog({
        width: 400,
        height: 420,
        buttons: "#bb",
        closed: true
    })
});



